<?php defined('SYSPATH') or die('No direct script access.');
 
/**
 * This is my custom controller with awesome stuff that I need.
 *   File name: MY_Controller.php
 */
class Controller extends Controller_Core {
	
	public $template = "";
	public $config = null;
	public $menus = null;
	public $blocos = null;
	public $view = null;
	
	public function __construct(){
		parent::__construct();
		
		$cfg = ORM::factory('config')->find();
		Kohana::config_set('config.site_template', $cfg->template);
		$this->config = $cfg;
		$this->template = $cfg->template;
		$menus = ORM::factory('menu')
						->where('ativo', '1')
						->find_all();
		$this->menus = $menus;
		$this->blocos = ORM::factory('bloco')
						->where('ativo', '1')
						->find_all();
	}

	public function create_view($tpl=""){
		if($tpl==""){
			$this->view = new View($this->template.'/pagina');
		}else{
			$this->view = new View($this->template.'/'.$tpl);
		}

		$this->view->cabecalho  = new View($this->template.'/cabecalho');
		$this->view->menu_esq = new View($this->template.'/menu_esq');
		$this->view->bloco  = new View($this->template.'/bloco');
		//$this->view->menu_dir = new View($this->template.'/menu_dir');
		$this->view->rodape  = new View($this->template.'/rodape');
		
		$this->view->menu_esq->menus = $this->menus;
		$this->view->cabecalho->title = $this->config->title;
		$this->view->cabecalho->cabecalho = $this->config->header;
		$this->view->rodape->rodape = $this->config->footer;
	}
}